<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class User extends Controller
{
    public function index()
    {
        // 原生查询
//        $list = Db::query('SELECT * FROM user WHERE id=?', [17]);
//        助手函数查询
        $list = db('user')->order(['id' => 'ASC'])->select();
        dump($list);

    }

    public function insert()
    {
//        原生插入

//        $res = Db::execute('INSERT INTO user (id,name,tel,age,sex) VALUES (:id, :name, :tel, :age, :sex)', ['id' => null, 'name' => '万能', 'tel' => 15677777777, 'age' => 19, 'sex' => 1]);
        $data = [
            'name' => '王帆2',
            'tel' => 18999799989,
            'age' => 18,
            'sex' => 1
        ];

//        DB类插入
//        $res = Db::table('user')->insert($data);
//        $res = Db::table('user')->insertGetID($data);
//     助手函数
        $res = db('user')->insertGetId($data);
        dump($res);

    }

    public function delete()
    {
//        DB删除
//        $res = DB::table('user')->delete(35);
//        助手函数删除
        $res = db('user')->delete(34);
        var_dump($res);

    }

    public function updata()
    {
//        $res = DB::table('user')->where('id', '31')->update(['name' => '洋洋']);
        $res = db('user')->where('id', '33')->update(['name' => '狗狗']);
        var_dump($res);

    }
}
